package classic150;

/**
 * <h3>leetcode</h3>
 *
 * @author BigFaceCat
 * @date 2023/11/1 20:51
 * @description <p>leetcode88-合并两个有序数组-数组-简单题</p>
 */
public class No88 {
    public static void main(String[] args) {
        int[] a = {1, 2, 0, 0, 0};
        int m = 2;
        int[] b = {2, 5, 6};
        int n = 3;
        merge(a, m, b, n);
    }

    public static void merge(int[] n1, int m, int[] n2, int n) {
        int p1 = 0;
        int p2 = 0;
        int temp;
        int[] list = new int[m + n];

        while (p1 < m || p2 < n) {
            if (p1 == m) {
                temp = n2[p2++];
            } else if (p2 == n) {
                temp = n1[p1++];
            } else if (n1[p1] < n2[p2]) {
                temp = n1[p1++];
            } else {
                temp = n2[p2++];
            }
            list[p1 + p2 - 1] = temp;
        }

        for (int i = 0; i < m + n; i++) {
            n1[i] = list[i];
            System.out.print(list[i]);
        }

    }
}